"""
    使用python内置库中的堆结构查找最大和最小的n个元素，并测试api
    当n为1时 使用min max速度更快，若n接近列表长度，排序后切片速度更快
"""
import heapq
import random

tmp = [random.randint(0,100) for _ in range(15)]
print(tmp)

print(heapq.nlargest(5,tmp))
print(heapq.nsmallest(5,tmp))
print('*'*20)

heapq.heapify(tmp)
print(tmp)
print(heapq.heappop(tmp))
print(tmp)
print(heapq.heappop(tmp))
print(tmp)
heapq.heappush(tmp,100)
print(tmp)